home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
utmisc2
/
since.lha
/
Since.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1996-05-19
|
8KB
|
294 lines
/*
Shows how many days/weeks/months/years have past since certain events
occurred. (or until coming future events.)
Your personalized list might look something like:
> Dentist visit... 8.0 months ago.
> Eye examine..... 11.4 months ago.
> Physical........ 5.2 months ago.
> Pay Raise....... 6.6 months ago.
> Marriage........ 9.4 years ago.
> My Retirement... 23.1 years from now.
> Oil change...... 33.0 days ago.
> Next Birthday... 1.9 months from now.
> End of Century.. 3.6 years from now.
> Christmas....... 7.8 months from now.
> Taxes Due....... 11.0 months from now.
You make a config file called s:since.dat that looks like:
> 12-May-1995 Dentist visit
> 15-Aug-1995 Eye examine
> 20-Nov-1995 Physical
> 08-Jan-1996 Oil change
"Since" uses options like:
> SHOW (Show the output.)
> EDIT (Edit any 1 line of the config file.)
> HELP (Show a help-screen.)
> ADD (Add 1 line to the config file.)
> CONFIG=s:since.dat (Use this config file.)
> FIND=taxes (Find and display lines contain this word.)
All dates in s:since.dat config must occur between 01-Jan-1978 and 31-Dec-2100.
Installation:
Copy since.rexx TO rexx:
Copy since.dat TO s:
Create a DOS alias like: Alias since rx rexx:since.rexx SHOW
$VER: Since.rexx v1.0 19-May-96 by Bill Beogelein
First public release version. (to aminet)
$VER: Since.rexx v0.9 29-Apr-96 by Bill Beogelein
Beta-test version.
Author Info:
Bill Beogelein
Box 530441
Livonia, MI 48153 USA
SysOp of The Amiga ShareWare HeadQuarters BBS 28k8 1-810-473-2020
Fido: 1:2410/207, Internet: ag775@detroit.freenet.org
Future Plans:
Send suggestions for new features (and bug reports) to the address above.
Re-write in C.
Also re-save comments also.
Also allow (and hide) comments at the ends of lines.
If bad date found, allow editing or removal.
Add NoFIND=string option.
If passed a valid date, show since/ago days.
Ignore:
lha u dh6:a/6.6/since.lha Rexx:since.rexx up:since.dat up:since.readme
*********************** End of docs *******************************/
call Init()
/************** Top of user-definable variables ******************/
def_config = "s:Since.dat" /* Use this default config file if none is specified */
dy_limit = 90 /* After x days, display using "weeks" */
wk_limit = 12 /* After x weeks, display using "months" */
mo_limit = 10 /* After x months, display using "years" */
width = 1 /* Width of "123.45 date" decimal places (Default==1) */
/************** End of user-definable variables ******************/
parse arg opts
o_add = GetSwitch(opts, "ADD" , 0)
o_edit = GetSwitch(opts, "EDIT" , 0)
o_show = GetSwitch(opts, "SHOW" , 0)
o_help = GetSwitch(opts, "HELP" , 0)
o_config = GetKeyWrd(opts, "CONFIG=", def_config)
o_find = GetKeyWrd(opts, "FIND=" , "-")
o_find = upper(o_find)
if(o_help) then
do
say ""
address command "Version rexx:Since.rexx FULL FILE"
say ""
say " ADD : Add new dates and text."
say " EDIT : Edit dates and text."
say " SHOW : Show dates."
say " HELP : Displays this help-screen."
say ""
say " FIND=string : Only display lines containing this string."
say " CONFIG=s:fName : Use this config file." LF
say " Format used in config is: 20-May-1997 The String To Display." LF
exit
end
if(o_show | o_find~="-") then call ShowDates()
if(o_edit) then call Edit()
if(o_add ) then call Add()
exit /*** End of main ***/
Add:
do i=1 to 999
mode='Writing'; if(exists(o_config)) then mode='Appending'
say "" mode "new events to" o_config "..." LF
say " Format is: 20-May-1997 The String To Display."
call writeCH(STDOUT, " New Event: ")
ans = readLN(STDIN)
if(ans=="") then
do
say LF "*** Ending new additions." BELL LF
return
end
if(open(fp, o_config, mode)) then
do
call writeLN(fp, ans)
call close(fp)
end
else
say LF "*** Rexx:since.rexx can't open" o_config "for" mode BELL LF
end
return
Load:
libname="rexxsupport.library"
if( ~show('LIBRARIES', libname) ) then
if( ~addlib(libname, 0, -30) ) then
do
say LF "*** Rexx:Since.rexx can't open libs:" || libname BELL LF
exit
end /* Leave loaded */
if(open(fp, o_config, 'READ')) then
do
configCount=0
maxWidth=2
do i=1 to 9999
buf = strip(readLN(fp))
if(eof(fp)) then leave
if(buf == "") then iterate
if(left(buf, 1) == ';') then iterate
configCount= configCount+1
config.configCount = buf
/* say aaa buf zzz */
w= length(buf)
if(w>maxWidth) then maxWidth=w
dt= left(buf,2) /* 12345678901 */
yr= substr(buf,8,4) /* 12-Apr-1996 */
if(yr<1978 | yr>2099 | dt<1 | dt>31) then
do
say LF "*** Rexx:Since.rexx detects date outside of" LF "*** legal range (1978-2100) in" o_config "..." LF buf LF BELL
exit
end
end
call close(fp)
end
else
do
say LF "*** Rexx:Since.rexx can't open" o_config "for reading." BELL LF
exit
end
return
Save:
if(open(fp, o_config, 'WRITE')) then
do
say LF "Saving to" o_config "..."
do i=1 to configCount
call writeLN(fp, config.i)
say right(i || ")" ,3) config.i
end
call close(fp)
end
else
do
say LF "*** Rexx:Since.rexx can't open" o_config "for writing." BELL LF
exit
end
return
Edit:
call ShowDates()
call writeCH(STDOUT, "Edit which: ")
ans = readLN(STDIN)
if(ans=="") then
do
say LF "*** Edit aborted." BELL LF
return
end
say LF "Old:" config.ans
call writeCH(STDOUT, " New: ")
new = strip(readLN(STDIN))
if(new == "") then
do
say LF "*** Edit aborted." BELL LF
return
end
call writeCH(STDOUT, " Save" new "([y]es/[N]o)? ")
confirm = left(upper(readLN(STDIN)),1)
if(confirm=='Y') then
do
config.ans = new
call Save()
end
else
say LF "*** Edit aborted." BELL LF
return
ShowDates:
call Load()
do i=1 to configCount
diff= date('INTERNAL') - Date2Int(word(config.i,1))
if(o_edit) then
counter= right(i || ")", 3)
else
counter=""
if(pos(o_find,upper(config.i))>0) then
say counter left(config.i, maxWidth+2, '.') || Shorten(diff)
end
return
GetSwitch: PROCEDURE EXPOSE opts
parse arg opts, str, def
w=find(upper(opts), upper(str))
if(w<1) then return def
opts=delword(opts, w, 1)
return ~(def) /*** End of GetSwitch ***/
GetKeyWrd: PROCEDURE EXPOSE opts
parse arg opts, str, def
p=pos(upper(str), upper(opts))
if(p<1) then return def
len=length(str)
s=word(substr(opts, p+len),1)
opts=delstr(opts, p, len+length(s)+1)
return s /*** End of GetKeyWrd ***/
Shorten: PROCEDURE EXPOSE c30 c365 width dy_limit wk_limit mo_limit
parse arg days /* Convert days into "xx.x yrs/mos/wks/etc" */
past= "ago."
if(days<0) then
do
past="from now."
days= days*(-1)
end
str= right(trunc(days , width), width+4) "days"
if(days > dy_limit) then str= right(trunc(days/7 , width), width+4) "weeks"
if(days > 7 *wk_limit) then str= right(trunc(days/c30 , width), width+4) "months"
if(days > c30*mo_limit) then str= right(trunc(days/c365, width), width+4) "years"
return str past
Date2Int: PROCEDURE /* Convert 31-Dec-1995 into internal date */
parse arg dat
dat= upper(dat)
dt = left(dat,2)
mo = substr(dat,4,3)
yr = right(dat,4) /* if(yr<79) then yr=yr+2000; else yr=yr+1900 */
p = pos(mo, "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC")
p = (p%3)+1
mo= right(p, 2, '0')
sort= yr || mo || dt /* 19941231 */
return date('INTERNAL', sort, 'SORTED')
Init:
LF = '0a'x
BELL = '07'x
c365 = 365.25
c30 = c365/12 /* Avg # of days in 1 month */
return
/*** End of Rexx:Since.rexx by Bill Beogelein 810-473-2020 ***/